package com.djdevs.calculatorconverter;

public class ConverterParser {
	public ConverterParser() { }
	
	private String _baseUnit;
	private String _baseUnitCode;
	private double _baseUnitValue;
	private double _baseUnitFactor;
	
	private String _firstUnit;
	private String _firstUnitCode;
	private double _firstUnitValue;
	private double _firstUnitFactor;
	
	private String _secondUnit;
	private String _secondUnitCode;
	private double _secondUnitValue;
	private double _secondUnitFactor;
	
	public double getSecondUnitValue() {
		return this._secondUnitValue;
	}
	
	public double getFirstUnitValue() {
		return this._firstUnitValue;
	}
	
	public void SetBaseUnit(String baseUnit, String baseUnitCode, Double baseUnitValue, Double baseUnitFactor)
	{
		this._baseUnit = baseUnit;
		this._baseUnitCode = baseUnitCode;
		this._baseUnitValue = baseUnitValue;
		this._baseUnitFactor = baseUnitFactor;
	}
	
	public void SetFirstUnit(String firstUnit, String firstUnitCode, Double firstUnitValue, Double firstUnitFactor)
	{
		this._firstUnit = firstUnit;
		this._firstUnitCode = firstUnitCode;
		this._firstUnitValue = firstUnitValue;
		this._firstUnitFactor = firstUnitFactor;
	}
	
	public void SetSecondUnit(String secondUnit, String secondUnitCode, Double secondUnitValue, Double secondUnitFactor)
	{
		this._secondUnit = secondUnit;
		this._secondUnitCode = secondUnitCode;
		this._secondUnitValue = secondUnitValue;
		this._secondUnitFactor = secondUnitFactor;
	}
	
	public void ConvertUnit()
	{
		ConvertFirstToBaseUnit();
		ConvertBaseToSecondUnit();
	}
	
	private void ConvertFirstToBaseUnit()
	{
		if (_firstUnitFactor > 1.0) {
			_baseUnitValue = _firstUnitValue / _firstUnitFactor;
		}
		else {
			_baseUnitValue = _firstUnitValue * _firstUnitFactor;
		}
	}
	
	private void ConvertBaseToSecondUnit()
	{
		if (_secondUnitFactor > 1.0) {
			_secondUnitValue = _baseUnitValue / _secondUnitFactor;
		}
		else {
			_secondUnitValue = _baseUnitValue * _secondUnitFactor;
		}
	}
}
